import { constructProxy } from './proxy.js'
import { mount } from './mount.js'
// 为Hue的原型添加init方法
let uid = 0
export function initMixin(Hue) {
  Hue.prototype._init = function (options) {
    const vm = this
    vm.uid = ++uid
    vm._isHue = true
    // 初始化data
    if (options && options.data) {
      vm._data = constructProxy(vm, options.data, null)
    }
    // 初始化created方法
    if (options && options.created) {
      vm._created = options.created
    }
    // 初始化methods
    if (options && options.methods) {
      vm._methods = options.methods
      for (const key in options.methods) {
        vm[key] = options.methods[key]
      }
    }
    // 初始化computed
    if (options && options.computed) {
      vm._computed = options.computed
      for (let temp in options.computed) {
        vm[temp] = options.computed[temp]
      }
    }
    // 初始化el并挂载
    if (options && options.el) {
      let rootDom = document.getElementById(options.el)
      mount(vm, rootDom)
    }
  }
}